import com.imooc.spring.jdbc.dao.EmployeeDao;
import com.imooc.spring.jdbc.entity.Employee;
import com.imooc.spring.jdbc.service.EmployeeService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class JdbcTemplateTestor {
    @Resource
    private EmployeeDao employeeDao;
    @Resource
    private EmployeeService employeeService;

    @Test
    public void testFindById() {
        Employee employee = employeeDao.findById(3308);
        System.out.println(employee);
    }

    @Test
    public void testFindByDename() {
        List<Employee> list = employeeDao.findByDename("市场部");
        System.out.println(list);

    }

    @Test
    public void testUpdate() {
        Employee employee = employeeDao.findById(3610);
        employee.setSalary(employee.getSalary() + 1000);
        int count = employeeDao.update(employee);
        System.out.println(count);
    }

    @Test
    public void testInsert() {
        Employee employee = new Employee();
        employee.setEno(8888);
        employee.setEname("赵六");
        employee.setDename("市场部");
        employee.setSalary(5000.00F);
        employee.setHiredate(new Date());
        int count = employeeDao.insert(employee);
        System.out.println(count);
    }

    @Test
    public void tesDelete() {
        int count = employeeDao.delete(8888);
        System.out.println(count);
    }

    @Test
    public void tesBathImport() {
        employeeService.batchImport();
        System.out.println("批量导入成功");
    }


}
